package sipoc.messaging.component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.Header;
import org.springframework.integration.annotation.Payload;
import org.springframework.integration.annotation.Transformer;
import org.springframework.stereotype.Component;

import sipoc.license.LicenseManager;
import sipoc.model.HbResponse;
import sipoc.model.HbResponseValue;

@Component
public class HbTransformer {
	@Autowired
	private LicenseManager licenseManager;

	private static final Logger LOGGER = LoggerFactory
			.getLogger(HbTransformer.class);

	@Transformer(inputChannel = "transformerChannel")
	public HbResponse transform(@Header String countryCode,
			@Payload HbResponseValue response) {
		LOGGER.info("Request in transformer");

		HbResponse hbResponse;

		switch (response) {
		case LICENSE_OK:
			hbResponse = new HbResponse("Hb successfully");
			break;
		case INVALID_LICENSE:
			hbResponse = new HbResponse("Hb failed: license not acquired");
			break;
		default:
			hbResponse = new HbResponse("Hb failed");
		}

		return hbResponse;
	}
}
